//
//  MainViewController.swift
//  sinaweibowj
//
//  Created by Macintosh on 15/12/12.
//  Copyright © 2015年 mactoinsh. All rights reserved.
//

import UIKit 

class MainViewController: UITabBarController {

     let mainTabBar = MainTabBar()
    
    //swift方法选择器和访问控制关键字能够兼容 需要使用@objc
    //
    @objc private func composeBtnDidClick(){
    
        print(__FUNCTION__)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //tabBar是只读属性 不能够被赋值 利用KVC 在运行时 间接赋值
        print(tabBar.classForCoder)
        
        mainTabBar.composeBtn.addTarget(self, action: "composeBtnDidClick", forControlEvents: .TouchUpInside)
        
        setValue(mainTabBar, forKey: "tabBar")
        print(tabBar.classForCoder)
        //添加子视图控制器
        addChildViewControllers()
        
    }
    
    //private表示只能在本类中进行访问
    private func addChildViewControllers() {
        
        addChildViewController(HomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoveryViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileViewContrller(), title: "我", imageName: "tabbar_profile")
        
    }

    
    
    private func addChildViewController(vc: UIViewController, title:String ,imageName:String) {
        
        self.tabBar.tintColor = UIColor.orangeColor()
        let nav = UINavigationController(rootViewController:
        vc)
        
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)
        
        addChildViewController(nav)
        
    }
    
}
